class Solution
{
public:
    int numRabbits(vector<int> &answers)
    {
        unordered_map<int, int> colorGroups;
        int result = 0;
        for (int colorGroup : answers)
        {
            colorGroup += 1;
            ++colorGroups[colorGroup];
            if (colorGroups[colorGroup] == colorGroup)
            {
                result += colorGroup;
                colorGroups[colorGroup] = 0;
            }
        }
        for (auto [colorGroup, count] : colorGroups)
        {
            if (count != 0)
            {
                result += colorGroup;
            }
        }
        return result;
    }
};